package com.bit.principle.controller;

import com.bit.principle.model.Dog;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dog")
public class DogController {

    @Autowired
    private ApplicationContext context;
    @Resource(name = "singletonDog")
    private Dog singletonDog;

    @Resource(name = "prototypeDog")
    private Dog prototypeDog;

    @Resource(name = "requestDog")
    private Dog requestDog;

    @Resource(name = "sessionDog")
    private Dog sessionDog;

    @Resource(name = "applicationDog")
    private Dog applicationDog;

    @RequestMapping("/single")
    public String singleDog(){
        Dog contextDog = (Dog)context.getBean("singletonDog");
        return "contextDog:" + contextDog +", ResourceDog:" + singletonDog;
    }

    @RequestMapping("/prototype")
    public String prototype(){
        Dog contextDog = (Dog)context.getBean("prototypeDog");
        return "contextDog:" + contextDog +", ResourceDog:" + prototypeDog;
    }

    @RequestMapping("/request")
    public String request(){
        Dog contextDog = (Dog)context.getBean("requestDog");
        return "contextDog:" + contextDog +", ResourceDog:" + requestDog;
    }

    @RequestMapping("/session")
    public String session(){
        Dog contextDog = (Dog)context.getBean("sessionDog");
        return "contextDog:" + contextDog +", ResourceDog:" + sessionDog;
    }

    @RequestMapping("/applicationDog")
    public String applicationDog(){
        Dog contextDog = (Dog)context.getBean("applicationDog");
        return "contextDog:" + contextDog +", ResourceDog:" + applicationDog;
    }
}
